#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 思考一下能否写出一个@log的decorator，使它既支持有文本参数，又支持无文本参数
import functools
import time


def log(param=''):
    if callable(param):

        @functools.wraps(param)
        def wrapper(*arg, **kw):
            print('call %s:' % param.__name__)
            return param(*arg, **kw)

        return wrapper
    elif isinstance(param, str):

        def decorator(func):
            @functools.wraps(func)
            def wrapper(*args, **kw):
                print('%s %s():' % (param, func.__name__))
                return func(*args, **kw)

            return wrapper

        return decorator


@log
def now():
    print('now,time is ' + time.strftime('%Y-%m-%d %H:%M:%S',
                                         time.localtime(time.time())))


now()
time.sleep(1)


@log('execute')
def now():
    print('now,time is ' + time.strftime('%Y-%m-%d %H:%M:%S',
                                         time.localtime(time.time())))


now()